package com.wink.file.center.config;

import com.wink.file.center.constant.enums.FileType;
import com.wink.file.center.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * oss服务工厂
 *
 * @author wink
 * @date 2020/11/17 17:46:48
 */
@Configuration
public class OssServiceFactory {

	private Map<FileType, FileService> map = new ConcurrentHashMap<>();

 
	@Autowired
	@Qualifier("aliyunOssServiceImpl")
	private FileService aliyunOssServiceImpl;

	@Autowired
	@Qualifier("localOssServiceImpl")
	private FileService localOssServiceImpl;

	@PostConstruct
	public void init() {
		map.put(FileType.ALIYUN,  aliyunOssServiceImpl);
		map.put(FileType.LOCAL ,  localOssServiceImpl);
		// map.put(FileType.QINIU ,  qiniuOssServiceImpl);
		// map.put(FileType.FASTDFS ,  fastDfsOssServiceImpl);
	}

	public FileService getFileService(Integer fileType) {
		return map.get(FileType.findByCode(fileType));
	}
}
